﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using abdalla_VoteModel;

public partial class Vote : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Ask_Click(object sender, EventArgs e)
    {
        using (abdalla_VoteEntities DM = new abdalla_VoteEntities())
        {
            Que_table_abdo q1 = new Que_table_abdo();
            q1.Question = AskTextBox.Text;
            q1.username = "ahmed";
            DM.AddToQue_table_abdo(q1);
            DM.SaveChanges();
            GridView1.DataBind();
        }
    }
    protected void Answer_Click(object sender, EventArgs e)
    {
        using (abdalla_VoteEntities DM = new abdalla_VoteEntities())
        {
            ANS_Table_Abdo a1 = new ANS_Table_Abdo();
            int ss = (int)GridView1.SelectedValue;
            a1.ID = ss;
            a1.Answer = TextBox1.Text;
            a1.Username = "Ahmed";

            DM.AddToANS_Table_Abdo(a1);
            DM.SaveChanges();
            GridView2.DataBind();
            Label3.Text = ss.ToString();

        }
    }





    protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
    {

    }

    
    protected void Button1_Click(object sender, EventArgs e)
    {
        ahooo.Visible = true;

    }



    protected void Ahoo_click(object sender, EventArgs e)
    {
        using (abdalla_VoteEntities DB = new abdalla_VoteEntities())
        {

            int i = (int)(GridView2.SelectedValue);
            ANS_Table_Abdo a3 = new ANS_Table_Abdo();
            a3 = (from mt in DB.ANS_Table_Abdo where mt.Answer_ID == i select mt).FirstOrDefault();
            a3.vote_counter++;
            //DB.ANS_Table_Abdo.AddObject(a3);
            DB.SaveChanges();
            ahooo.Visible=false;
        }
  
        
    
    }



}





   


   
    
  





   

   


